const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    selected:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      let that = this;
      let d=app.globalData;
          this.setData({
              platform:d.platform,    
              width:d.windowWidth,
              height:d.windowHeight,
              statusBarHeight:d.statusBarHeight,
              navHeight:d.navHeight,
              marginTop:d.navTitleTop,
              domain:d.domain,
              iUrl:d.iUrl,
              upUrl:d.upUrl
            })
  },
  goBack(){
    var pages = getCurrentPages();
    console.log(pages);
    wx.navigateBack();
},
goto:function(e){
    console.log(e);
    var url=e.currentTarget.dataset.url;
    var index=e.currentTarget.dataset.index;
    app.goto(url,index)
},
  select:function(e){
    var selected=this.data.selected;
    if(selected==false){
      selected=true;
    }else{
      selected=false;
    }
    this.setData({
      selected:selected
    })
  },
  getPhoneNumber:function (e) {
    var open =  wx.getStorageSync('open');
    console.log(e);
       wx.request({
                url:app.globalData.domain+'/wechat/login/getPhone',
                data:{
                    'code':e.detail.code,
                    'id':open.id,        
                },
                method:'GET',
                header:{
                    'content-type':'application/json'
                },
                success:function(res){
                  console.log(res)
                    //wx.setStorageSync('PhoneNumber',res.data.phone);
                    if(res.data.code==200){
                      open.phone = res.data.phone;
                      wx.setStorageSync('open', res.data.open);
                      wx.setStorageSync('user', res.data.user);
                      wx.showToast({
                        title: '登陆成功',
                        success:function(res){
                          wx.navigateBack();
                        }
                      })
                    }else{
                      wx.showToast({
                        title: '登陆失败'
                      })
                    } 
                    //console.log("手机号为");
                    //console.log(res);
                },
                fail:function(err){
                    console.log(err);
                }
            })
          
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var open = wx.getStorageSync('open');
    this.setData({
        open:open
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})